package org.lgiavedoni.android.franq.core.listener;

import lombok.Synchronized;

import org.lgiavedoni.android.franq.service.phone.ContextService;

import android.content.BroadcastReceiver;
import android.content.IntentFilter;

public abstract class PhoneBroadcastListener extends BroadcastReceiver implements PhoneListener {

	private boolean listening = false;

	public abstract IntentFilter getListenetFilter();

	@Override
	@Synchronized
	public synchronized void registerListener() {
		//synchronized (registred) {
			if (!listening) {
				ContextService.inst.getApplicationContext().registerReceiver(this, getListenetFilter());
				listening = true;
			}

		//}
	}

	@Override
	@Synchronized
	public synchronized void unregisterListener() {
		//synchronized (registred) {
			if (listening) {
				ContextService.inst.getApplicationContext().unregisterReceiver(this);
				listening = false;
			}
		//}
	}
	
	public boolean isListening() {
		return listening;
	}

}
